package com.neusoft.util;

import java.util.Properties;

import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.Message.RecipientType;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

public class MailUtil {
	
	public static void sendMail(String mail,String code) {
		
		Properties props = new Properties();
		props.setProperty("mail.host", "localhost");
		Session session = Session.getInstance(props, new Authenticator() {
			@Override
			protected PasswordAuthentication getPasswordAuthentication() {
				// TODO Auto-generated method stub
				return new PasswordAuthentication("service@daqi.com", "123");
			}
		});
		Message message = new MimeMessage(session);
		try {
			message.setFrom(new InternetAddress("service@shop.com"));
			message.addRecipient(RecipientType.TO, new InternetAddress(mail));
			message.setSubject("来自fly社区的激活邮件");
			message.setContent("<h1>fly社区官方激活邮件，点下面的链接完成激活操作</h1><h3><a href='http://localhost:8080/neusoft_fly/user/user_active?code="+code+"'>http://localhost:8080/neusoft_fly/user/user_active?code="+code+"</a></h3>", "text/html;charSet=utf-8");
			//message.setContent(arg0, "text/plain");
			Transport.send(message);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
	}

}
